package logic

import (
	"context"
	"wechat/models/mysql"

	"wechat/wechatrpc/internal/svc"
	"wechat/wechatrpc/wechatrpc"

	"github.com/zeromicro/go-zero/core/logx"
)

type MomentsAddLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewMomentsAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MomentsAddLogic {
	return &MomentsAddLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *MomentsAddLogic) MomentsAdd(in *wechatrpc.MomentsAddRequest) (*wechatrpc.MomentsAddResponse, error) {
	// todo: add your logic here and delete this line

	var findUser mysql.User

	if err := findUser.FindUserById(mysql.DB, in.UserId); err != nil {
		return nil, err
	}

	moment := &mysql.Moments{
		Image:   in.Image,
		Article: in.Article,
	}

	if err := moment.MomentAdd(mysql.DB); err != nil {
		return nil, err
	}

	return &wechatrpc.MomentsAddResponse{
		MomentId: int64(moment.ID),
	}, nil
}
